<?php

if ($_REQUEST['action'] = "list")
{
	if ($db = new SQLiteDatabase('InstantInput.db')) 
	{
		$result = $db->query("SELECT * FROM User_Classes WHERE sunet_id='". $_ENV["WEBAUTH_USER"]  ."'");	
		print json_encode(sqlite_fetch_all($result));
	} 
	else 
	{
	    die($err);
	}
}
	
if ($_REQUEST['action'] = "add_user")
{
	if ($db = new SQLiteDatabase('InstantInput.db')) 
	{
		$command = "Insert INTO Users (sunet_id, type, email) VALUES (" . $_ENV["WEBAUTH_USER"] . ", " . $_ENV["WEBAUTH_LDAPAUTHRULE"] . ", " . $_ENV["WEBAUTH_LDAP_MAIL"] . ")";	
		$db->queryExec($command);
	} 
	else 
	{
	    die($err);
	}
}	

if ($_REQUEST['action'] = "add_class")
{
	if ($db = new SQLiteDatabase('InstantInput.db')) 
	{
		$command = "Insert INTO User_Classes (class_code, class_name, teacher) VALUES (" . $REQUEST['class_code'] . ", " . $REQUEST["class_name"] . ", " . $REQUEST["teacher"] . ")";	
		$db->queryExec($command);
	} 
	else 
	{
	    die($err);
	}
}	

//Remove class
//$db->queryExec("DELTE FROM User_Classes WHERE clsas_id = AND sunet_id = ")
	
?>